
package com.guoxin.zuche;

import java.util.concurrent.ExecutorService;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
//意见反馈
public class FeedbackActivity extends Activity implements OnClickListener{
	private final int SUBMIT_START_ID = 1;
	private final int SUBMIT_END_ID = 2;
	public  String id = "";
	public  String content ="";
	public  String email ="";
	private EditText propose_content = null;
	private EditText propose_email = null;
	private TextView back= null;
	private TextView button_submit = null;
	private TextView title_center = null;
	private ProgressDialog mProgress;
//	private ExecutorService executorService = GetSingleThreadPool.getInstance();
	
	public Handler resultHander = new Handler(){
		@Override
		public void handleMessage(Message msg) {
			super.handleMessage(msg);
			if(msg.what==SUBMIT_START_ID){
//				Toast.makeText(ProposeActivity.this,R.string.thank_you_for_your_feedback, 1).show();
				FeedbackActivity.this.finish();
			}
			if(msg.what==SUBMIT_END_ID){
//				Toast.makeText(ProposeActivity.this,R.string.failure_to_submit, 1).show();
			}
		}
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.setContentView(R.layout.propose);
		setViews();
		setOnClickListeners();
		
	}
	
	
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
	}



	private void  setViews(){
		back = (TextView) this.findViewById(R.id.title_btn_left);
		
		button_submit = (TextView) this.findViewById(R.id.title_btn_right);
//		button_submit.setBackgroundResource(R.drawable.title_btn_util);
		button_submit.setVisibility(View.VISIBLE);
		button_submit.setText("提交");
		title_center = (TextView) this.findViewById(R.id.title_text_center);
		title_center.setText("意见反馈");
		
		findViewById(R.id.title_btn_left).setOnClickListener(this);
		propose_content = (EditText) findViewById(R.id.propose_content);
		propose_email = (EditText) findViewById(R.id.propose_email);
	}
	
	private void  setOnClickListeners(){
		back.setOnClickListener(this);
		button_submit.setOnClickListener(this);
	}
	
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.title_btn_right:
			content = propose_content.getText().toString() + "@Device=" + Build.MODEL + "@Version=" + Build.VERSION.RELEASE
					+ "@SoftWareVersion=" + getVersionName();
			email = propose_email.getText().toString();
//			if(!StringTool.isMobileOrEmail(email)){
//        		Toast.makeText(ProposeActivity.this, "邮箱或手机号有错，请重新输入", 1).show();
//        		return;
//        	}
//			if (StringTool.isNull(propose_content.getText().toString())) {
//				Toast.makeText(this, R.string.thank_you_for_the_air_support, 1).show();
//			} else {
//				executorService.execute(new Thread() {
//					public void run() {
//						showProgress();
//						Boolean mBoolean = ServerInterface.setPropose(content + "::" + email).isSuccess();
//						if (mBoolean != null) {
//							if (mBoolean) {
//								resultHander.sendEmptyMessage(SUBMIT_START_ID);
//							} else {
//								resultHander.sendEmptyMessage(SUBMIT_END_ID);
//							}
//						}
//						hideProgress();
//					}
//				});
//
//			}
			break;
		case R.id.title_btn_left:
			this.finish();
			break;
		}
	}
	
    /**
     * 
     * 获取当前程序的版本号 �??
     */
    private String getVersionName(){
    	
    		String version ="";
            // 获取packagemanager的实�?
            PackageManager packageManager = getPackageManager();
            // getPackageName()是你当前类的包名�?代表是获取版本信�?
            PackageInfo packInfo;
			try {
				packInfo = packageManager.getPackageInfo(getPackageName(),0);
				version = packInfo.versionName;
			} catch (NameNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
            
            return version;
    }
    
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
    	if (keyCode == KeyEvent.KEYCODE_BACK) {
    		this.finish();
    		return true;
	    }else{
	    	return super.onKeyDown(keyCode, event);
	    }
    }
    
    /**
	 * 显示等待�?
	 * 
	 * @param title
	 * @param message
	 */
	protected void showProgress() {
		this.runOnUiThread(new Runnable() {
			

			public void run() {	
				mProgress = new ProgressDialog(FeedbackActivity.this);
				mProgress.requestWindowFeature(Window.FEATURE_NO_TITLE);
				mProgress.setMessage("正在提交，请稍等...");
				mProgress.show();
			}
		});
	}

	/**
	 * 取消等待�?
	 */
	protected void hideProgress() {
		
		this.runOnUiThread(new Runnable() {
			public void run() {
				if (mProgress != null) {
					mProgress.dismiss();
				}
			}
		});
	}
}
